faApp.controller('SimuSpnrCtrl',['$scope','simuService','roadVideoService','$location','$controller','$routeParams','$filter','$route',function($scope,simuService,roadVideoService,$location,$controller,$routeParams,$filter,$route) {
   
  $controller('BaseCtrl', {$scope: $scope}); 
  $scope.id = $routeParams.id;
  $scope.jjbm = $routeParams.jjbm;
  $scope.spnr = {};
  $scope.player = '';
  roadVideoService.list({isProduct:'0',pageSize:1000,pageNo:1}).then(function(json){
    $scope.list = json.list;
  });
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail;
    $scope.videoInfoPost = {
      productType:'01',
      productId:$scope.id
    }
    roadVideoService.videoIdbyPro($scope.videoInfoPost).then(function(json){
      $scope.oldId = json.dto ? json.dto.id : '';
      $scope.title = json.dto ? json.dto.title : '';

    })
  });



   $scope.save=function(){

      if($scope.newVideoId==null||$scope.newVideoId==''){
        alert("视频名称不能为空");
        return ;
      }
      $scope.spnr.productType="01";
      $scope.spnr.productId=$scope.id;
      $scope.spnr.oldId = $scope.oldId;
      $scope.spnr.id = $scope.newVideoId;
       roadVideoService.edit($scope.spnr).then(function(json){
         if(!json.statusCode){
           alert("修改成功");
           $route.reload()
         }else{
           alert(json.statusCode);
         }
       });
   }

   $scope.playVideo = function(v){
    if(!v){
      alert('请选择视频');
      return;
    }else{
      for( arr in $scope.list){
        if($scope.list[arr].id == v){
          $scope.videoId = $scope.list[arr].videoId;
        };
      }
    };
    if($scope.videoId){
      $scope.showPlayBox = true;
      $scope.player = new YKU.Player('youkuplayer',{
        styleid: '0',
        client_id: YK_CLIENT_ID,
        vid: $scope.videoId,
        newPlayer: true
      })
    }

  }

   $scope.stopPlay = function(){
     $scope.videoId = '';
     $scope.showPlayBox = false;
   }




}]);
